#!/usr/bin/env python

# $LastChangedBy: ben.trettel $
# $LastChangedRevision: 9 $
# $LastChangedDate: 2013-01-20 03:44:53 +0000 (Sun, 20 Jan 2013) $
# $HeadURL: http://medos.googlecode.com/svn/trunk/src/RestingRateModels.py $

"""
RestingRateModels.py: Models that predict rates needed to live
"""

# m is mass in kg; h is height in cm; t is age in years.
# gender is 1 for male; 0 for female.
# Returned value is in kcal/day.
def calculateMifflinREE(m, h, t, gender):
   if gender==0:
      s = 5
   elif gender==1:
      s = -161
   else:
      s = 0 # Don't know what to do here.  Should I assume they are always one or the other?
   return ( 9.99*m + 6.25*h - 4.92*t + s )

# Returned value is in kcal/day.
def calculateRevisedHarrisBenedictREE(m, h, t, gender):
   if gender==0:
      return ( 447.593 + 3.098*h + 9.247*m - 4.737*t )
   elif gender==1:
      return ( 88.362 + 4.799*h + 13.397*m - 5.677*t )
   else:
      return 0.0

# Returned value is in kcal/day.
def calculateREE(m, h, t, gender, method):
   if method.lower()=="mifflin":
      return calculateMifflinREE(m, h, t, gender)
   elif method.lower()=="revisedharrisbenedict":
      return calculateRevisedHarrisBenedictREE(m, h, t, gender)
   else:
      return 0.0

# Returned value is in ml/min.
def calculateRozaRestingVdotO2(m, h, t, gender):
   if gender==0:
      return ( 63.23 + 0.457*h + 1.318*m - 0.621*t )
   elif gender==1:
      return ( 12.04 + 0.687*h + 1.929*m - 0.802*t )
   else:
      return 0.0

# Returned value is in ml/min.
def calculateRestingVdotO2(m, h, t, gender, method):
   if method.lower()=="roza":
      return calculateRozaRestingVdotO2(m, h, t, gender)
   else:
      return 0.0

# Returned value is in ml/kg/min.
def calculateSpecificRestingVdotO2(m, h, t, gender, method):
   return ( calculateRestingVdotO2(m, h, t, gender, method) / m )
